package api

import (
	"go-weiqi-system/config"
	"go-weiqi-system/internal/models"
	"go-weiqi-system/internal/utils"

	"github.com/gin-gonic/gin"
)

type IndexController struct{}

// Index 首页数据
func (ctrl *IndexController) Index(c *gin.Context) {
	// 轮播图
	var banners []models.Banner
	config.DB.Where("status = ?", 1).
		Order("sort desc, id desc").
		Limit(5).
		Find(&banners)

	// 推荐课程
	var courses []models.Course
	config.DB.Where("status = ?", 1).
		Order("sort desc, id desc").
		Limit(3).
		Find(&courses)

	// 热门比赛
	var competitions []models.Competition
	config.DB.Where("status = ? AND competition_status = ?", 1, "未开始").
		Order("sort desc, id desc").
		Limit(3).
		Find(&competitions)

	// 活动计划
	var activities []models.Activity
	config.DB.Where("status = ?", 1).
		Order("sort desc, id desc").
		Limit(5).
		Find(&activities)

	utils.Success(c, gin.H{
		"banners":      banners,
		"courses":      courses,
		"competitions": competitions,
		"activities":   activities,
	})
}

// BannerList 轮播图列表
func (ctrl *IndexController) BannerList(c *gin.Context) {
	var banners []models.Banner
	config.DB.Where("status = ?", 1).
		Order("sort desc, id desc").
		Find(&banners)

	utils.Success(c, banners)
}
